<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户编辑</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<style type="text/css">
.content-tab ul {
	padding: 0px;
	margin: 0px;
}
span.datebox{
	height:30px!important;
}
span.datebox span a.textbox-icon{
	height:30px!important;
}
span.datebox input.textbox-text{
	padding-top:8px!important;
}
</style>
</head>
<body>
	<div>
		<!--导航栏-->
		<div class="line10"></div>
		<!--/导航栏-->

		<!--内容-->
		<div id="floatHead" class="content-tab-wrap">
			<div class="content-tab">
				<div class="content-tab-ul-wrap">
					<ul>
						<li><a class="title selected" href="javascript:;">用户编辑</a></li>
					</ul>
				</div>
			</div>
		</div>

		<div class="tab-content">
			<dl>
				<dt>编码</dt>
				<dd>
					<input id="CODE" class="input normal"></input><span
						class="Validform_checktip"> *必填，用户登录账号</span>
				</dd>
			</dl>
			<dl>
				<dt>姓名</dt>
				<dd>
					<input id="NAME" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>
 			<dl>
				<dt>密码</dt>
				<dd>
					<input id="PASSWORD" type="password" class="input normal"></input>
					<span class="Validform_checktip">*必填，用户登录密码</span>
				</dd>
			</dl> 
			<dl>
				<dt>确认密码</dt>
				<dd>
					<input id="PASSWORD1" type="password" class="input normal"></input>
					<span class="Validform_checktip">*必填</span>
				</dd>
			</dl> 
			<dl>
				<dt>出生日期</dt>
				<dd>
					<input id="BIRTHDAY" class="easyui-datebox" type="text"></input>
				</dd>
			</dl>
			<dl>
				<dt>身份证号</dt>
				<dd>
					<input id="ID_NUMBER" class="input normal"></input>
				</dd>
			</dl>
			<dl>
				<dt>手机号</dt>
				<dd>
					<input id="PHONE_NUMBER" class="input normal"></input>
				</dd>
			</dl>
			<dl>
				<dt>注册日期</dt>
				<dd>
					<input id="CREATE_DATE" disabled="disabled" class="input normal" type="text"></input>
				</dd>
			</dl>
			<dl>
				<dt>上次登录日期</dt>
				<dd>
					<input id="LAST_LOGIN_DATE" disabled="disabled" class="input normal" type="text"></input>
				</dd>
			</dl>
		</div>
		<!--/内容-->

		<!--工具栏-->
		<div class="page-footer">
			<div class="btn-wrap">
				<button class="btn" onclick="save()">提交保存</button>
				<button class="btn yellow" onclick="javascript:history.back(-1);">返回上一页</button>
			</div>
		</div>
		<!--/工具栏-->
	</div>
	<input type="hidden" id="action" value="${action}"/>
	<input type="hidden" id="hidCode" value="${userId}"/>
	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	    var contextPath = '<%=request.getContextPath()%>';
	    var action=$('#action').val();
	    var hidCode=$('#hidCode').val();
		$(document).ready(function() {
			//校验新增用户编码是否已经存在
			$('#CODE').blur(function(){
				if(action=='add'){
					if(!$.isNullOrEmpty($('#CODE').val())){
						$.ajax({
							url : contextPath + "/bg/U104.do",
							data : {"CODE":$('#CODE').val(),"rnd":Math.random()},
							dataType : 'json',
							success : function(data, textStatus, jqXHR) {
								if(data.status=='true'){
									$.messager.show({title:'提示',msg:'编码已存在！',showType:'slide'});
									$('#CODE').val('');
									$('#CODE').focus();
								}
							}
						});
					}
				}
			});
			if(action=='add'){
				$('a.title').html('新增用户');
				$('#CREATE_DATE').parents('dl').css('display','none');
				$('#LAST_LOGIN_DATE').parents('dl').css('display','none');
			}else{
				$('a.title').html('查看用户');
				$('#CODE').val(hidCode);
				$('#CODE').attr("disabled","disabled");
				$.ajax({
					url : contextPath + "/bg/U104.do",
					data : {"CODE":hidCode,"rnd":Math.random()},
					dataType : 'json',
					success : function(data, textStatus, jqXHR) {
						var record = data.record;
						if(data.status=='true'){
							$('#NAME').val(record.NAME);
							$('#BIRTHDAY').val(record.BIRTHDAY);
							$('#PASSWORD').val(record.PASSWORD);
							$('#PASSWORD1').val(record.PASSWORD);
							$('#BIRTHDAY').datebox('setValue',record.BIRTHDAY);
							$('#ID_NUMBER').val(record.ID_NUMBER);
							$('#PHONE_NUMBER').val(record.PHONE_NUMBER);
							$('#LAST_LOGIN_DATE').val(record.LAST_LOGIN_DATE);
							$('#CREATE_DATE').val(record.CREATE_DATE);
						}
					}
				});
			}
		})

		//提交保存
		function save() {
			var param = {};
			param.CODE = $('#CODE').val();
	  		if($.isNullOrEmpty(param.CODE)){
	  			$.messager.show({title:'提示',msg:'编码不能为空！',showType:'slide'});
	  			$('#CODE').focus();
	  			return;
	  		}
	  		param.NAME = $('#NAME').val();
	  		if($.isNullOrEmpty(param.NAME)){
	  			$.messager.show({title:'提示',msg:'姓名不能为空！',showType:'slide'});
	  			$('#NAME').focus();
	  			return;
	  		}
	  		param.PASSWORD = $('#PASSWORD').val();
	  		if($.isNullOrEmpty(param.PASSWORD)){
	  			$.messager.show({title:'提示',msg:'密码不能为空！',showType:'slide'});
	  			$('#PASSWORD').focus();
	  			return;
	  		}
	  		var PASSWORD1 = $('#PASSWORD1').val();
	  		if($.isNullOrEmpty(PASSWORD1)){
	  			$.messager.show({title:'提示',msg:'确认密码不能为空！',showType:'slide'});
	  			$('#PASSWORD1').focus();
	  			return;
	  		}
	  		if(param.PASSWORD!=PASSWORD1){
	  			$.messager.show({title:'提示',msg:'密码与确认密码不符，请重新输入！',showType:'slide'});
	  			$('#PASSWORD1').focus();
	  			return;
	  		}
			param.PHONE_NUMBER = $('#PHONE_NUMBER').val();
			param.ID_NUMBER = $('#ID_NUMBER').val();
			param.BIRTHDAY = $('#BIRTHDAY').datebox('getValue');
			param.CREATE_DATE = $('#CREATE_DATE').val();
			param.rnd = Math.random();
			$.ajax({
				url : contextPath + "/bg/U103.do",
				data : param,
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {	
					if(data.status=='true'){
						if(action=='add'){
							$.messager.show({title:'提示',msg:'新增用户成功！',showType:'slide'});
						}
						else{
							$.messager.show({title:'提示',msg:'修改用户成功！',showType:'slide'});
						}
						//location.href=contextPath+"/bg/user.do";
					}else{
						if(action=='add'){
							$.messager.show({title:'提示',msg:'新增用户失败！',showType:'slide'});
						}
						else{
							$.messager.show({title:'提示',msg:'修改用户失败！',showType:'slide'});
						}
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					$.messager.show({title:'提示',msg:'失败！',showType:'slide'});
				}
			});
		}
	</script>
</body>
</html>